<template>
  <div>
<h2>修改页面</h2>
<table border="1">
  <tr>
    <td>房型名称</td>
    <td>
      <input type="text" v-model="state.rname">
    </td>
  </tr>
  <tr>
    <td>简介</td>
    <td>
      <input type="text" v-model="state.remark">
    </td>
  </tr>
 
  <tr>
    <td></td>
    <td>
      <input type="button" @click="upd" value="修改">
    </td>
  </tr>
</table>
  </div>
</template>

<script setup lang="ts">
import { reactive,toRefs,onMounted } from 'vue';
import axios from 'axios';
import { useRoute,useRouter } from 'vue-router';
let route=useRoute();
let router=useRouter();
let data=reactive({
  state:{
  rname: '',
  price: '',
  picture: '',
  maxnum: '',
  squre: '',
  remark: '',
  cretatime: '',
 
  },

})
let {state}=toRefs(data)
function upd()
{
  let obj={
  "id":route.query.id,
 "rname": state.value.rname,
  "price": state.value.price,
  "picture": state.value.picture,
  "maxnum": state.value.maxnum,
  "squre": state.value.squre,
  "remark": state.value.remark,
  "cretatime": state.value.cretatime
  }
  
  axios({
    url:'/api/RoomType/Update',
    method:'post',
    data:obj
  })
  .then(res=>{
    if(res.data.data==1)
  {
    alert("修改成功")

    router.push("../show")
  }
  
  else
  {
    alert("修改失败")
  }
  })
  .catch(err=>{

  })
}
onMounted (()=>{
  getAll()
})
const getAll:any=()=>{
  let obj={
    id:route.query.id
  }
  axios({
    url:'/api/RoomType/Fantian',
    method:'get',
    params:obj
  })
  .then(res=>{
    state.value=res.data.data
  })
  .catch(err=>{

  })
}

</script>

<style scoped>

</style>